package com.example.osixaffairssystem.service.impl;

import com.example.osixaffairssystem.domain.PageBean;
import com.example.osixaffairssystem.domain.model.Std;
import com.example.osixaffairssystem.mapper.StdMapper;
import com.example.osixaffairssystem.service.StdService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@RequiredArgsConstructor
public class StdServiceImpl implements StdService {

    final StdMapper stdMapper;

    @Override
    public List<Std> list() {
        return stdMapper.list();
    }

    @Override
    public PageBean<Std> listToPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        Page<Std> p = (Page<Std>) stdMapper.list();
        return new PageBean<>(p.getTotal(), p.getResult());
    }

    @Override
    public Integer insert(Std std) {
        stdMapper.insert(std);
        return std.getId();
    }

    @Override
    public void update(Std std) {
        stdMapper.update(std);
    }

    @Override
    public PageBean<Std> search(String no, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        Page<Std> p = (Page<Std>) stdMapper.search(no);
        return new PageBean<>(p.getTotal(), p.getResult());
    }

    @Override
    public void delete(List<Integer> ids) {
        stdMapper.delete(ids);
    }


}
